package server;

import java.sql.ResultSet;
import java.sql.SQLException;

public class BankStaffList {
	private Data data;
	
	public BankStaffList(){
		data=new Data();
	}

	public boolean addStaff(int ID,String name,int key){
		//添加一个员工
		String sql;
		int re=0;
		BankAccList acclist=new BankAccList();
		int caNum=acclist.getCANum(ID);
		
		sql="insert into bankstafflist values (null,"+ID+","+caNum+","+key+",'"+name+"')";
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
	}
	
	public boolean searchID(int pID){
		//在职工表中检索ID是否存在，存在则返回true
		String sql;
		ResultSet rs=null;
		
		sql="select * from bankstafflist where pID=" + pID;
		rs=data.getResultSet(sql);
		try {
			if(rs.next()){
				return true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return false;
		
	}
	
	public int getKey(int pID){
		//参数ID,返回员工表的密码key
		String sql;
		ResultSet rs=null;
		int pkey=0;
		
		sql="select * from bankstafflist where pID=" + pID+" limit 1";
		rs=data.getResultSet(sql);
		try {
			if(rs.next()){
				pkey=rs.getInt("enterkey");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return pkey;
	}
	
	public boolean deleteStaff(int pID){
		//从员工表中删除ID为pID的项
		String sql;
		int re=0;
		
		sql="delete from bankstafflist where pID="+pID;
		re=data.update(sql);
		
		if(re==1){
			return true;
		}
		return false;
	}
	
	public int getSize(){
		String sql;
		ResultSet rs=null;
		int sum=0;
		
		sql="select count(*) as sum from bankstafflist";
		rs=data.getResultSet(sql);
		try {
			if(rs.next()){
				sum=rs.getInt("sum");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return sum;
	}
	
}
